import { NodeSize } from '../config'

export default function excelInput(flow) {
  flow.register('ExcelInput', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#DBF3DB',
              d: 'M711.92381 329.142857h-104.838096V224.304762H282.819048v594.895238h270.628571l177.980952-177.980952-19.504761 17.066666V329.142857z m-143.84762 326.704762l-' +
                '68.266666-104.838095-68.266667 104.838095h-36.571428l85.333333-131.657143-80.457143-129.219047h36.571429l63.390476 102.4 65.828571-102.4h36.571429l-' +
                '82.895238 129.219047 85.333333 131.657143h-36.571429z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M889.904762 804.571429v75.580952l-126.780952-126.780952-34.133334 31.695238 129.219048 129.219047H780.190476v46.32381h156.038095V804.571429zM282.819048 ' +
                '819.2V224.304762h324.266666v104.838095h104.838096V658.285714l17.066666-17.066666 24.380953-21.942858V329.142857l-41.447619-41.447619h-63.390477V224.304762l-' +
                '41.447619-41.447619h-365.714285v677.790476H512l41.447619-41.447619z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M602.209524 397.409524h-36.571429l-63.390476 99.961905-65.828571-99.961905h-36.571429l82.895238 126.780952-85.333333 131.657143h36.571428l68.266667-' +
                '104.838095 65.828571 104.838095h36.571429l-85.333333-131.657143z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          'Excel输入'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
